package com.hk.commons.dto;

import com.hk.commons.enums.Whether;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

/**
 * Created by Antinomy on 16/11/16.
 */
public class QueryPagingDTO extends DateRangeDTO {

    @ApiModelProperty(value="当前页码")
    protected Integer curPage = 0;

    @ApiModelProperty(value="每页数量")
    protected Integer pageSize = 10;

    @ApiModelProperty(value="排序字段")
    protected String orderBy = "id";

    @ApiModelProperty(value="升序 ASC / 降序 DESC")
    protected String xsc;

    @ApiModelProperty(value="关键字")
    protected String keyword;

    @ApiModelProperty(value="是否删除")
    private Whether deleted = Whether.NO;

    @ApiModelProperty(value="uuid")
    private String uuid;

    public Integer getCurPage() {
        return curPage;
    }

    public void setCurPage(Integer curPage) {
        this.curPage = curPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getXsc() {
        return xsc;
    }

    public void setXsc(String xsc) {
        this.xsc = xsc;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public Whether getDeleted() {
        return deleted;
    }

    public void setDeleted(Whether deleted) {
        this.deleted = deleted;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Pageable getPage() {
        Sort sort = new Sort(Sort.Direction.DESC, orderBy);
        return new PageRequest(curPage, pageSize, sort);
    }
}
